//
//  EDMyEditInfoViewController.m
//  EasyDeliver
//
//  Created by 王森林 on 2018/11/26.
//  Copyright © 2018年 chenhongwei. All rights reserved.
//

#import "EDMyEditInfoViewController.h"
#import <ReactiveObjC/ReactiveObjC.h>
#import <Masonry/Masonry.h>
#import "YQBPlaceTextView.h"
#import "UserRes.h"
#define MAX_LIMIT_NUMS 25
@interface EDMyEditInfoViewController ()<UITextFieldDelegate,UITextViewDelegate>
@property (nonatomic, strong) UITextField *textf;
@property (nonatomic, strong)  UserRes *user;
//@property (nonatomic, strong) YQBPlaceTextView *textview;
//@property (nonatomic, strong) UILabel *limitLab;
//@property (nonatomic, strong) UIButton *commitBtn;//保存按钮
@end

@implementation EDMyEditInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"编辑";
    self.user = [CommonMethod getUser];
    if (!self.user) {
        [[NSNotificationCenter defaultCenter]postNotificationName:NotificationCenterName_AlertLoginVC object:nil];
        return;
    }
//    UIView *underline = [[UIView alloc]init];
//    underline.backgroundColor = [UIColor colorWithRed:234.0/255.0 green:234.0/255.0 blue:234.0/255.0 alpha:1];
    
   
    
    UIView  *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 45)];
    bgView.backgroundColor  = [UIColor whiteColor];
//    bgView.layer.borderColor = [UIColor colorWithHexString:@"#ebebeb"].CGColor;
    [self.view addSubview:bgView];
    
    UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 44.5, BOUNDWIDTH, 0.5)];
    lineLabel.backgroundColor = Common_SepeColor;
    [bgView addSubview:lineLabel];
    
    
    self.textf = [[UITextField alloc] init];
     self.textf.clearButtonMode = UITextFieldViewModeAlways;
    self.textf.frame = CGRectMake(15, 0, self.view.frame.size.width-30, 45);
//    self.textf.backgroundColor = [UIColor whiteColor];
//    self.textf.layer.borderWidth  = 0.5;
//    self.textf.layer.borderColor = [UIColor colorWithHexString:@"#ebebeb"].CGColor;
   
    self.textf.font = [UIFont systemFontOfSize:15];
    [bgView addSubview:self.textf];
    
    
    [self setNaviDefaultRightBtnWithTitle:@"保存" andSel:@selector(onLoginEvent:)];
    
    switch (self.type) {
        case 1:
        {
            self.title = @"修改昵称";
            self.textf.placeholder =  @"请输入昵称";
            if (![CommonMethod isBlankString:self.user.USER.NICK00]) {
                self.textf.text = self.user.USER.NICK00;
            }
            
        }
            break;
        case 2:
        {
            self.title = @"修改地区";
            self.textf.placeholder =  @"请输入地区";
            if (![CommonMethod isBlankString:self.user.USER.DQ0000]) {
                self.textf.text = self.user.USER.DQ0000;
            }
           
            
        }
            break;
        case 3:
        {
            self.title = @"修改行业";
            self.textf.placeholder =  @"请输入行业";
            if (![CommonMethod isBlankString:self.user.USER.HY0000]) {
                self.textf.text = self.user.USER.HY0000;
            }
            

            
        }
            break;
            
        default:
            break;
    }
    
    
    
}


- (void)onLoginEvent:(UIButton *)sender
{
    
    
    
    //保存信息
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:[CommonMethod createMD5Key:@"USERNAME"] forKey:@"FKEY"];
    [params setObject:self.user.mobile forKey:@"USERNAME"];
    switch (self.type) {
        case 1:
        {
            [params setObject:self.textf.text forKey:@"NICK00"];
        }
            break;
        case 2:
        {
           [params setObject:self.textf.text forKey:@"DQ0000"];
        }
            break;
        case 3:
        {
            [params setObject:self.textf.text forKey:@"HY0000"];
        }
            break;
            
            
        default:
            break;
    }
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [SVProgressHUD showWithStatus:nil];
    });
    
    [[ZY_AfnNetManager shareInstance]postWithURL:Car_API_23 params:params md5Paraname:nil success:^(id  _Nullable response) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
        });
     
        
        if (self.editCallBack) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [SVProgressHUD showInfoWithStatus:@"更新成功"];
//                [SVProgressHUD dismissWithDelay:10];
            });
          
            [self.navigationController popViewControllerAnimated:YES];
            self.editCallBack(self.textf.text);
        }
        
        
    } fail:^(NSError * _Nonnull error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [SVProgressHUD showErrorWithStatus:error.localizedDescription];
        });
        
    }];
    
    
   
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
